<template>
	<view class="chat">
		<rui-side ref="refSide"></rui-side>
		<rui-chat-header @side="onSide"></rui-chat-header>
		<rui-chat-message>
			<rui-chat-message-advert :data="user.welcome"></rui-chat-message-advert>
		</rui-chat-message>
		<rui-chat-input @send="send"></rui-chat-input>
	</view>
</template>
<script setup>
	import {
		ref
	} from "vue";
	import {
		userStore,
		chatStore
	} from "@/store/index.js"
	
	import Push from "@/util/push.js"

	const user = userStore();
	const chat = chatStore();
	const push = new Push();
	
	
	//连接服务器
	if(user.isLogin) {
		push.start();
	}
	
	const refSide = ref();
	const onSide = () => {
		if (!user.isLogin) {
			uni.$rui.route('/pages/user/login/login')
			return;
		}
		refSide.value.open()
	}
	
	const emits = defineEmits(['change'])

	const send = (msg) => {
		push.send(msg)
		emits('change', msg)
	}
</script>
<style lang="scss" scoped>
	.chat {
		padding: 60rpx 0 100rpx;
	}
</style>